<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/common/head.jsp" %>
<style>
	.memberlist .row {
		background:#fff;border-bottom:1px solid #ccc;padding:10px 0;margin-left:0px;
	}
</style>
<div id="wizard" style="width:70%;margin-top:20px;">
    <form id="companyform" action="form_wizard.html#" class="wizard-big">
    <input type="hidden" id="userId" />
       <h1>添加信息</h1>
       <fieldset style="position:relative;">
           <h5>公司信息</h5>
           <div class="row">
               <div class="col-sm-12">
                   <div class="form-group">
                       <label>手机号码 *</label>
                       <input id="mobile" name="mobile" type="text" class="form-control required">
                   </div>
                   <div class="form-group">
                       <label>公司名称 *</label>
                       <input id="name" name="name" type="text" class="form-control required">
                   </div>
                   <div class="form-group">
                       <label class="form-group">公司所在地 *</label>
                       <div class="form-group">
	                       <div class="col-sm-4" style="padding-left:0;">
								<select name="province.id" class="form-control required" id="provinceId" onchange="selectProvince(this);">
									<option value="">请选择省</option>
									<c:forEach items="${provinces }" var="p">
										<option value="${p.id }" >${p.name }</option>
									</c:forEach>
								</select>						                 	
			             	</div>	
							<div class="col-sm-4">
			                 	<select name="city.id" class="form-control required" id="cityId" onchange="selectCity(this);">
			                 		<option value="${city.id }">${city.name }</option>
								</select>	
				             </div>	
							<div class="col-sm-4">
			                 	<select name="district.id" class="form-control required" id="districtId">
			                 		<option value="">请选择区县</option>
				                 	<c:forEach items="${districts }" var="d">
				                 	<option value="${d.id }">${d.name }</option>
				                 	</c:forEach>
								</select>
				             </div>	
				        </div>
                   </div>
                   <div class="form-group">
                       <label class="companylabel">公司注册地址 *</label>
                       <input id="registerAddress" name="registerAddress" type="text" class="form-control required">
                   </div>
                   <div class="form-group">
                       <label>公司办公地址 *</label>
                       <input id="officeAddress" name="officeAddress" type="text" class="form-control required">
                   </div>
                   <div class="form-group">
                       <label>销售类型 *</label>
                       <!-- <input id="confirm" name="confirm" type="text" class="form-control required"> -->
                       ${enum:detail('CompanySalesType', 'salesType', n.salesType) }
                   </div>
                   <div class="form-group">
                       <label>公司网址 </label>
                       <input id="webSite" name="webSite" type="text" class="form-control">
                   </div>
                   <div class="form-group">
                       <label>公司人数 </label>
                       ${enum:detail('CompanyQuantity', 'quantity', n.quantity) }
                   </div>
                   <div class="form-group">
                       <label>公司行业 </label>
                       ${enum:detail('CompanyIndustry', 'industry', n.industry) }
                   </div>
                   <div class="form-group">
                       <label>公司性质 </label>
                       ${enum:detail('CompanyNature', 'nature', n.nature) }
                   </div>
                   <div class="form-group">
              			<label class="col-sm-12">证件上传*</label>
                  		<div class="col-sm-12">
					        <input type="hidden" name="images" id="images" value="${n.images }" />
			                <div class="my-images" single="false" images="${n.images }" id="image" field="images">
			                </div>
		                </div>
                   </div>
                   <div class="form-group">请将营业执照、组织机构代码证、税务登记证、一般纳税人证明、开户许可证、
开票信息及法人身份证的电子版上传（附件请不要超过10M）</div>
                   <div class="form-group">
                       <label>备注</label>
                       <input id="remark" name="remark" type="text" class="form-control">
                   </div>
                   <!-- <div class="form-group">
                   		<label>验证码*</label>
                   		<input id="confirm" name="confirm" type="text" class="form-control">
                   </div> -->
               </div>
           </div>

       </fieldset>
       <h1>缴费</h1>
       <fieldset class="memberlist" style="position:relative;">
           <h5>会员清单</h5>
           <div class="row">
               <div class="col-sm-6">
               		<label>会员信息</label>
               </div>
               <div class="col-sm-3">
                   <label>金额（元）</label>
               </div>
               <div class="col-sm-3">
                   <label>支付方式</label>
               </div>
           </div>
           <div class="row">
               <div class="col-sm-6">
               		<span style="display:block;" id="username"><!-- 名称：某某装修软装公司 --></span>
               		<span style="display:block;" id="address"><!-- 地址：广东省 广州市 --></span>
               		<!-- <span style="display:block;">电话：020-23434563</span> -->
               </div>
               <div class="col-sm-3">
                   <span class="form-group" style="line-height:60px;">¥ 20000</span>
               </div>
               <div class="col-sm-3">
                   <span class="form-group" style="line-height:60px;">在线</span>
               </div>
           </div>
           <div class="form-group">
               <label style="line-height:40px;">添加会员备注</label>
               <input id="remark" name="remark" type="text" class="form-control required">
           </div>
           <hr/>
           <div class="form-group">
               <label class="col-sm-8"></label>
               <div class="col-sm-4">
               		<label>应付总额：¥ 20000</label><a class="btn btn-danger" id="commitOrder">提交订单</a>
               </div>
           </div>
       </fieldset>

       <h1>待审核</h1>
       <fieldset>
           <div class="text-center" style="margin-top: 120px">
           		<i class="glyphicon glyphicon-ok" style="color:#1AB394;font-size:30px;"></i>
               <h2>已提交资料</h2>
               <h5>（审核需两天工作日）</h5>
           </div>
       </fieldset>

       <h1>完成</h1>
       <fieldset>
       		<div class="text-center" style="margin-top: 120px">
	           <i class="glyphicon glyphicon-ok" style="color:#1AB394;font-size:30px;"></i>
	           <h2>完成！</h2>
           </div>
       </fieldset>
   </form>
</div>
<script>
function selectProvince(_this){
	var $this = $(_this);
	var provinceId = $this.val();
	$('#cityId').html('');
	$('#districtId').html('');
	if (provinceId != '') {
		$.ajax({
			url: "${ctx}/admin/province/findArea?provinceId=" + provinceId,
			dataType: "json",
			success: function(array) {
				$('#cityId').append('<option value="">城市</option>');
				for (var i = 0; i < array.length; i++) {
					var obj = array[i];
					var option = '<option value="' + obj.id + '">' + obj.name + '</option>';
					$('#cityId').append(option);	
				}
			}
		});
	}
}
function selectCity(_this) {
	var $this = $(_this);
	var cityId = $this.val();
	$('#districtId').html('');
	if (cityId != '') {
		$.ajax({
			url: "${ctx}/admin/province/findArea?cityId=" + cityId,
			dataType: "json",
			success: function(array) {
				$('#districtId').append('<option value="">地区</option>');
				for (var i = 0; i < array.length; i++) {
					var obj = array[i];
					var option = '<option value="' + obj.id + '">' + obj.name + '</option>';
					$('#districtId').append(option);	
				}
			}
		});
	}
}

$(document).ready(function() {
	init_images('image');
});

var index = ${startIndex};

$("#companyform").steps({
    bodyTag: "fieldset",
    startIndex: index,
    onStepChanging: function (event, currentIndex, newIndex) {
    	if (currentIndex > newIndex || currentIndex > 1) {
            return true;
        }
		var form = $(this);
        if (currentIndex < newIndex) {
            $(".body:eq(" + newIndex + ") label.error", form).remove();
            $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
        }
        form.validate().settings.ignore = ":disabled,:hidden";
        var valid = form.valid();
        var provinceId = $('#provinceId').val();
        var cityId = $('#cityId').val();
        var districtId = $('#districtId').val();
        if(!!!provinceId || !!!cityId || !!!districtId) {
        	error('请填写必要的信息');
        	valid = false;
        	var name = !!!provinceId ? '省份' : '';
        	name = !!!cityId ? '城市' : name;
        	name = !!!districtId ? '区县' : name;
        	var label = $('.companylabel');
        	var errorEl = '<label id="username-error" class="error" for="username"><i class="fa fa-times-circle"></i>  必选' + name + '</label>';
        	$(errorEl).insertAfter(label);
        	return false;
        }
        var result = false;
        if(!!valid && valid != 'false' && currentIndex == 0) {
        	//保存数据
        	var params = $('#companyform').serialize();
        	$.ajax({
    			url: "${ctx}/admin/user/companySave",
    			dataType: 'json',
    			data : params,
    			async: false,
    			success: function(data) {
    				if(!!!data) {
    					result = false;
    				} else {
    					result = true;
    					$("#username").html("名称："+data.name);
    					$("#address").html("地址："+$("#provinceId").find("option:selected").text()
    					+$("#cityId").find("option:selected").text()+
    					$("#districtId").find("option:selected").text());
    					$("#userId").val(data.user.id);
    				}
    			}
    		}); 
        }
        return result;
    },
    onStepChanged: function (event, currentIndex, priorIndex) {
        /* if (currentIndex === 2 && Number($("#age").val()) >= 18) {
            $(this).steps("next");
        }

        // Suppress (skip) "Warning" step if the user is old enough and wants to the previous step.
        if (currentIndex === 2 && priorIndex === 3) {
            $(this).steps("previous");
        }  */
    },
    onFinishing: function (event, currentIndex) {
        /* var form = $(this);

        // Disable validation on fields that are disabled.
        // At this point it's recommended to do an overall check (mean ignoring only disabled fields)
        form.validate().settings.ignore = ":disabled";

        // Start validation; Prevent form submission if false
        return form.valid(); */
    },
    onFinished: function (event, currentIndex) {
        /* var form = $(this);

        // Submit form input
        form.submit(); */
    }
}).validate({
    errorPlacement: function (error, element) {
        element.before(error);
    },
    rules: {
        confirm: {
            equalTo: "#password"
        }
    }
});

$("#commitOrder").click(function(){
	var userId = $("#userId").val();
	location.href ="${ctx}/pay/setPayType?payType=1&payBizType=4&&amount=20000&userId="+userId;
});
</script>